<?php
$PHPSESSID = $_REQUEST ['extradata'];
session_id ( $PHPSESSID );
session_start ();
include_once ('config.php');
include_once( 'weibooauth.php' );
function JsonMessage($code, $message = null, $data = null, $ExtData = null) {
	$TmpJson = array ('Code' => $code, 'Message' => $message, 'Data' => $data );
	if ($ExtData && is_array ( $ExtData )) {
		foreach ( $ExtData as $key => $value ) {
			$TmpJson [$key] = $value;
		}
	}
	echo json_encode ( $TmpJson );
}
if (! isset ( $_SESSION ['last_key'] )) {
	$ErrorMessage = '用户未登录';
	JsonMessage ( 'Error', $PHPSESSID );
	die ();
}
if (! $img_data = file_get_contents($_FILES["Filedata"]["tmp_name"])) {
	$ErrorMessage = '上传图片失败';
	JsonMessage ( 'Error', $ErrorMessage );
	die ();
}
$s = new SaeStorage ();
$name = time() ;
if (! $s->write ( ST_DOMAIN, 'photo_' . $name . '.jpg', $img_data )){
	$ErrorMessage = '保存图片失败';
	JsonMessage ( 'Error', $ErrorMessage );
	die ();
}
$url = $s->getUrl ( ST_DOMAIN, 'photo_' . $name . '.jpg' );
$Data ['image_path'] = $url;
JsonMessage ( 'Succ', '图片上传成功!', $Data );
die ();